<template>
  <div>
    <Header/>
    <div class="mblog">
      <h2>{{blog.title}}</h2>
        <router-link :to="{name:'edit',params:{blogId:blog.id}}" v-if="ownBlog">
          <el-button type="success" size="mini">编辑此条</el-button>
        </router-link>
      <el-divider/>
      <div class="markdown-body" v-html="blog.content"></div>
    </div>
  </div>
</template>

<script>
import Header from "../components/Header";
import 'github-markdown-css/github-markdown.css'
export default {
  name: "BlogDetail",
  components: {Header},
  data(){
    return {
      blog:{
        title:'你好',
        content:'这里是内容',
      },
      ownBlog:false
    }
  },
  created() {
    const blogId = this.$route.params.blogId;
    if (blogId){
      this.$axios.get('/blog/'+blogId).then(res => {
        const blog = res.data.data;
        this.blog.id = blog.id;
        this.blog.title = blog.title;
        var MarkdownIt = require("markdown-it")
        var md = new MarkdownIt()
        var result = md.render(blog.content)
        this.blog.content = result;
        this.ownBlog = (blog.userId === this.$store.getters.getUser.id)
      })
    }
  }
}
</script>

<style scoped>
.mblog{
  box-shadow: 0 2px 12px 0 rgba(0,0,0,0.1);
  width: 100%;
  min-height: 700px;
  padding: 20px 15px;
}
</style>
